<?php
namespace CHOMP\SGIBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ComentarioType extends AbstractType
{	
	/**
	 * 
	 * @var SessionManager
	 * @DI\Inject("session.manager")
	 */
	public $sessionSvc;

	private $usuario;
	private $id;
	
	public function __construct($id, $sessionSvc){
    	$this->id = $id;
		$this->sessionSvc = $sessionSvc;
		$this->usuario = $this->sessionSvc->getCurrentUser();
	}    

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('comentario', 'text', array('required'  => true));
		$builder->add('usuario', 'entity', array(
				 'class'=>'CHOMPSGIBundle:Usuario',
				 'property'=>'login',
				 'query_builder' => function (\CHOMP\SGIBundle\Entity\UsuarioRepository $repository)
				 {
					 return $repository->createQueryBuilder('u')
							->where('u.empresa = ?1 AND u.id = '.$this->usuario->getId().' AND u.borrado = 0')
							->setParameter(1, $this->id);
				 }
				));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CHOMP\SGIBundle\Entity\Comentario',
        ));
    }
	
	public function getName()
    {
        return 'chomp_sgibundle_comentario';
    }
}
?>